package admin

import "object/go_cms/models"

type ArticleTypeController struct {
	BaseAdminController
	models models.ArticleTypeModels
}

/**
文章分类
*/
// @router /admin/article_type/indexUI [get]
func (c *ArticleTypeController) IndexUI() {
	c.TplAdmin("article/type_index")
}

// @router /admin/article_type/addUI [get]
func (c *ArticleTypeController) AddUI() {
	c.TplAdmin("article/type_add")
}

// @router /admin/article_type/editUI [get]
func (c *ArticleTypeController) EditUI() {
	c.TplAdmin("article/type_edit")
}

// @router /admin/article_type/get [get,post]
func (c *ArticleTypeController) Get() {
	c.Res.Code = 1
	c.Res.Msg = "获取成功"
	id, err := c.GetInt64("id")
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = "参数错误"
	} else {
		c.Res.Data, err = c.models.Get(id)
		if err != nil {
			c.Res.Code = 0
			c.Res.Msg = err.Error()
		}
	}
	c.Json(c.Res)
}

// @router /admin/article_type/query [get,post]
func (c *ArticleTypeController) Query() {
	c.Res.Code = 0
	c.Res.Msg = "获取成功"
	c.Res.Data, _ = c.models.Query()
	c.Json(c.Res)
}

// @router /admin/article_type/add [post]
func (c *ArticleTypeController) Add() {
	c.Res.Code = 1
	c.Res.Msg = "添加成功"
	maps := c.GetParamMap()
	row, err := c.models.Add(maps)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	} else {
		c.Res.Data = row
	}
	c.Json(c.Res)
}

// @router /admin/article_type/edit [post]
func (c *ArticleTypeController) Edit() {
	c.Res.Code = 1
	c.Res.Msg = "修改成功"
	maps := c.GetParamMap()
	row, err := c.models.Edit(maps)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	} else {
		c.Res.Data = row
	}
	c.Json(c.Res)
}

// @router /admin/article_type/delete [post]
func (c *ArticleTypeController) Delete() {
	c.Res.Code = 1
	c.Res.Msg = "删除成功"
	id, _ := c.GetInt64("id")
	_, err := c.models.Delete(id)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	}
	c.Json(c.Res)
}
